home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 025a / prgmchk.zip / PARENCHK.CMD < prev    next >
OS/2 REXX Batch file  |  1991-07-21  |  4KB  |  121 lines

  1. *(   PARENCHK.CMD - parentheses checker routine - This routine
  2.      compares number of ( vs number of ) per line and prints the line if the
  3.      totals don't agree:  If the totals are off but the line ends with a +
  4.      (Rbase continuation symbol) then the routine skips to the next line
  5.      before comparing totals.  The routine also checks the sequence of
  6.      opening and closing parentheses and flags the location within a line
  7.      where the number of closing exceeds the number of opening parentheses.
  8.                                             created 11 July 91; Wm Driskell)
  9.  
  10. set mess off
  11. set err mess off
  12. set err var verr
  13. set v blnk text = (char(32)), coma text = (char(44))
  14. set v lastchar text = .blnk
  15. set v oddchar = (char(254))
  16. set var plus = (char(43))
  17. set quote = .oddchar        *(oddchar=■)
  18. set zero on
  19. set v lineknt int = 0
  20. CLS
  21. WRITE ■Parentheses Checker■
  22. WRITE ■-------------------■
  23. WRITE ■ ■
  24.  
  25. fillin ifile$ using ■Enter name of file to check: ■
  26. fillin ofile$ using ■Enter name of file for output: ■
  27. out .ofile$
  28. write ■File: ■,.ifile$
  29. write ■ ■
  30. out scr
  31.  
  32. *( setup counters and constants )
  33. set v rpknt int = 0, lpknt int = 0
  34. set v lp$ text = (char(40))
  35. set v rp$ text = (char(41))
  36.  
  37. drop cursor c1
  38. drop tab t$$
  39. write ■loading the data...■
  40. create tab T$$ codeline text 100
  41. set delimit=.oddchar
  42. set blank =.oddchar
  43. load■t$$■from■.ifile$■as■ascii
  44. set■blank=.blnk
  45. set delimit=.coma
  46.  
  47. *( get line and parse for parentheses )
  48. out scr with .ofile$ append
  49. write ■Line #: total left paren and right paren counts■
  50. write ■-----------------------------------------------■
  51. out scr
  52. compute lk as rows from T$$
  53. *( get line and parse for parentheses )
  54.  declare c1 cursor for select codeline from t$$
  55.  open c1
  56.  fetch c1 into a$ ind1
  57. while sqlcode <> 100 then
  58.   set v lineknt = (.lineknt + 1)
  59.   write ■line■,.lineknt,■of■,.lk at 1 65 reverse
  60.   set v a$ = (strim(.a$))
  61.   set v vslen = (slen(.a$))
  62.   if (a$ not cont .lp$) and (a$ not cont .rp$) then
  63.     GOTO skipline
  64.   endif
  65.     set v l = (sloc(.a$,.lp$))
  66.     set v r = (sloc(.a$,.rp$))
  67.     set v b$ = .a$
  68.   while (.l + .r) > 0 then
  69.     IF l > 0 THEN
  70.      set v b$ = (sput(.b$,■!■,.l))
  71.      set v lpknt = (.lpknt + 1)
  72.     ENDIF
  73.     IF r > 0 THEN
  74.      set v b$ = (sput(.b$,■!■,.r))
  75.      set v rpknt = (.rpknt + 1)
  76.     ENDIF
  77.    IF r < l AND lpknt <= rpknt THEN
  78.      out scr with .ofile$ append
  79.      WRITE ■==>■, .lineknt, ■**** Too Many Right Parentheses ****■
  80.      WRITE .a$
  81.      set v c$ = (sfil(■.■,.vslen))
  82.      set v c$ = (sput(.c$,■^■,.r))
  83.      WRITE .c$
  84.      out scr
  85.    ENDIF
  86.     set v l = (sloc(.b$,.lp$))
  87.     set v r = (sloc(.b$,.rp$))
  88.   endwhile
  89.  LABEL skipline
  90.  set v lastchar = (sget(.a$,1,.vslen))      *(check for continuation char)
  91.  IF lpknt <> rpknt AND lastchar <> .plus THEN
  92.   out scr with .ofile$ append
  93.   WRITE ■==>■, .lineknt, ■: ■, .lpknt, .rpknt
  94.   WRITE .a$
  95.   out scr
  96.  ENDIF
  97.  fetch c1 into a$ ind1
  98. endwhile
  99. drop cursor c1
  100.  out scr with .ofile$ append
  101.  WRITE ■ ■
  102.  WRITE ■:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::■
  103.  WRITE ■ ■
  104.  WRITE ■total lines processed: ■,.lineknt
  105.  WRITE ■total number of parentheses: left - ■,.lpknt, ■right - ■,.rpknt
  106.  WRITE ■ ■
  107.  WRITE ■::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::■
  108.  WRITE ■ ■
  109.  out scr
  110.  set quote='
  111.  set mess on
  112.  set err mess on
  113. clear var blnk,plus,lastchar,oddchar,lineknt,a$,b$,lpknt,rpknt,lp$,rp$,l,r, +
  114. vsloc,vslen,ofile$,ifile$,ind1,lk,verr,coma
  115. return
  116.  
  117.  
  118.  
  119.  
  120.  
  121.